package com.jml.account.TypeHandles;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;



@MappedJdbcTypes(JdbcType.VARCHAR) //这个注解就是varchar类型以后就用自己的TypeHandler不用官方的
public class TestTypeHandle extends BaseTypeHandler  {
	//插入结果特殊处理
	@Override
	public void setNonNullParameter(PreparedStatement ps, int i, Object parameter,
			JdbcType jdbcType) throws SQLException {
		//设置插入数据库中的java的String类型后面都加 "-test"
		ps.setString(i,parameter+"-test");
	}
	//得到结果特殊处理
	@Override
	public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
		String result = rs.getString(columnName)+"myself";
		return result;
	}

	@Override
	public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
		return rs.getString(columnIndex);
	}

	@Override
	public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
		return cs.getString(columnIndex);
	}
}
